<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
            
    <script type="text/javascript">
    <!-- 
    $(document).ready(function() {
    	$('#doUpdateBtn').click(function() {
			//分公司代號
    		var securitiesNo = $('#securitiesNoUpdate').val();
			//分公司名稱    		
    		var securitiesName = $('#securitiesNameUpdate').val();
    		//聯絡人
    		var contactName = $('#contactNameUpdate').val();
    		//電話號碼
    		var contactTelno = $('#contactTelnoUpdate').val();
    		//手機號碼
    		var contactCellno = $("#contactCellnoUpdate").val();
    		//Email
    		var contactEmail = $('#contactEmailUpdate').val();
    		//地址
    		var securitiesAddress = $('#securitiesAddressUpdate').val();
    		//備註
    		var securitiesNoteCreate = $('#securitiesNoteUpdate').val();
    		//去掉空格    		
    		var value1 = securitiesNo.replace(/^\s+|\s+$/g,'');
    		var value2 = securitiesName.replace(/^\s+|\s+$/g,'');
    		var value3 = contactName.replace(/^\s+|\s+$/g,'');
    		var value4 = contactTelno.replace(/^\s+|\s+$/g,'');
    		var value5 = contactCellno.replace(/^\s+|\s+$/g,'');
    		var value6 = contactEmail.replace(/^\s+|\s+$/g,'');
    		var value7 = securitiesAddress.replace(/^\s+|\s+$/g,'');
    		var value8 = securitiesNoteCreate.replace(/^\s+|\s+$/g,'');
    		//驗證正則表達式,依次為郵件,聯繫電話,手機,分公司代號
    		var emailRegExp = /[a-zA-Z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?/;
			var ContactTelNoRegExp = /^0[0-9]{1,3}\-\d{5,8}$/;
			var GroupContactCellRegExp = /^09\d{8}$/;
			var securitiesNoRegExp = /^[0-9]{4}$/;
			//錯誤提示信息
    		var errorMessage = '';
    		/* 分公司代號驗證 */
    		if (value1 == '')
    		{
    		    if (errorMessage != '') errorMessage = errorMessage + '<br>';
    		    errorMessage = errorMessage + '分公司代號不可空白!!';
    		}else{
				 var count = securitiesNo.length;
				 var strLength = 0;					 
				 for(var i = 0; i < count; i++){
					  if(securitiesNo.charCodeAt(i) < 0 || securitiesNo.charCodeAt(i) > 255){
					   	strLength += 3;//漢字編碼在0-255之外，oracle數據庫是UTF-8編碼，一個漢字，對應數據庫varchar2的3個byte。
					  }else{
					  	 strLength += 1;
					  }
				 }
				 if(strLength != 4){
				 	 if (errorMessage != '') errorMessage = errorMessage + '<br>';
    		    	 errorMessage = errorMessage + '分公司代號為4碼!!';
				 }else if(!securitiesNoRegExp.test(value1)){
				 	if (errorMessage != '') errorMessage = errorMessage + '<br>';
    		    	errorMessage = errorMessage + '[分公司代號]格式錯誤,格式為xxxx,皆為數字!!';
				 }
    		}
    		/* 分公司名稱驗證 */    		
            if (value2 == '')
    		{
    		    if (errorMessage != '') errorMessage = errorMessage + '<br>';
    		    errorMessage = errorMessage + '分公司名稱不可空白!!';
    		}else{
				 var count = securitiesName.length;
				 var strLength = 0;					 
				 for(var i = 0; i < count; i++){
					  if(securitiesName.charCodeAt(i) < 0 || securitiesName.charCodeAt(i) > 255){
					   	strLength += 3;//漢字編碼在0-255之外，oracle數據庫是UTF-8編碼，一個漢字，對應數據庫varchar2的3個byte。
					  }else{
					  	 strLength += 1;
					  }
				 }
				 if(strLength > 200){
				 	 if (errorMessage != '') errorMessage = errorMessage + '<br>';
    		    	 errorMessage = errorMessage + '分公司名稱不可超過200碼!!';
				 }
    		} 
    		/* 聯絡人驗證 */
            if (value3 == '')
    		{
    		    if (errorMessage != '') errorMessage = errorMessage + '<br>';
    		    errorMessage = errorMessage + '聯絡人不可空白!!';
    		}else{
				 var count = contactName.length;
				 var strLength = 0;					 
				 for(var i = 0; i < count; i++){
					  if(contactName.charCodeAt(i) < 0 || contactName.charCodeAt(i) > 255){
					   	strLength += 3;//漢字編碼在0-255之外，oracle數據庫是UTF-8編碼，一個漢字，對應數據庫varchar2的3個byte。
					  }else{
					  	 strLength += 1;
					  }
				 }
				 if(strLength > 50){
				 	 if (errorMessage != '') errorMessage = errorMessage + '<br>';
    		    	 errorMessage = errorMessage + '聯絡人不可超過50碼!!';
				 }
    		} 
    		/* 電話號碼驗證 */
            if (value4 == '')
    		{
    		    if (errorMessage != '') errorMessage = errorMessage + '<br>';
    		    errorMessage = errorMessage + '電話號碼不可空白!!';
    		}else {
    			if(!ContactTelNoRegExp.test(contactTelno)){
						if (errorMessage != '') errorMessage = errorMessage + '<br>';
							errorMessage = errorMessage + '[電話號碼]格式錯誤,格式為0x-xxxxxxxx!!';
	 			}else{
				 var count = contactTelno.length;
				 var strLength = 0;					 
				 for(var i = 0; i < count; i++){
					  if(contactTelno.charCodeAt(i) < 0 || contactTelno.charCodeAt(i) > 255){
					   	strLength += 3;//漢字編碼在0-255之外，oracle數據庫是UTF-8編碼，一個漢字，對應數據庫varchar2的3個byte。
					  }else{
					  	 strLength += 1;
					  }
				 }
				 if(strLength > 30){
				 	 if (errorMessage != '') errorMessage = errorMessage + '<br>';
    		    	 errorMessage = errorMessage + '電話號碼不可超過30碼!!';
				 }
			 }
    		}     		
    		/* 手機號碼驗證 */
            if (value5 == '')
    		{
    		    if (errorMessage != '') errorMessage = errorMessage + '<br>';
    		    errorMessage = errorMessage + '手機號碼不可空白!!';
    		}else {
    		
				if(!GroupContactCellRegExp.test(contactCellno)){
					if (errorMessage != '') errorMessage = errorMessage + '<br>';
							errorMessage = errorMessage + '[手機號碼]格式錯誤,格式為09xxxxxxxx!!';
				}else{
				 var count = contactCellno.length;
				 var strLength = 0;					 
				 for(var i = 0; i < count; i++){
					  if(contactCellno.charCodeAt(i) < 0 || contactCellno.charCodeAt(i) > 255){
					   	strLength += 3;//漢字編碼在0-255之外，oracle數據庫是UTF-8編碼，一個漢字，對應數據庫varchar2的3個byte。
					  }else{
					  	 strLength += 1;
					  }
				 }
				 if(strLength > 30){
				 	 if (errorMessage != '') errorMessage = errorMessage + '<br>';
    		    	 errorMessage = errorMessage + '手機號碼不可超過30碼!!';
				 }
			 }
    		}     	
    		/* E-MAIL驗證 */
            if (value6 == '')
    		{
    		    if (errorMessage != '') errorMessage = errorMessage + '<br>';
    		    errorMessage = errorMessage + 'E-MAIL不可空白!!';
    		}else{
    			 if(!emailRegExp.test(contactEmail)){
    				 if (errorMessage != '') errorMessage = errorMessage + '<br>';
    		    	 errorMessage = errorMessage + '[E-MAIL]格式錯誤!!';
    			 }else{
				 var count = contactEmail.length;
				 var strLength = 0;					 
				 for(var i = 0; i < count; i++){
					  if(contactEmail.charCodeAt(i) < 0 || contactEmail.charCodeAt(i) > 255){
					   	strLength += 3;//漢字編碼在0-255之外，oracle數據庫是UTF-8編碼，一個漢字，對應數據庫varchar2的3個byte。
					  }else{
					  	 strLength += 1;
					  }
				 }
				 if(strLength > 100){
				 	 if (errorMessage != '') errorMessage = errorMessage + '<br>';
    		    	 errorMessage = errorMessage + 'E-MAIL不可超過100碼!!';
				 }
			   }
    		}       		
    		/* 地址驗證 */
            if (value7 == '')
    		{
    		    if (errorMessage != '') errorMessage = errorMessage + '<br>';
    		    errorMessage = errorMessage + '地址不可空白!!';
    		}else{
				 var count = securitiesAddress.length;
				 var strLength = 0;					 
				 for(var i = 0; i < count; i++){
					  if(securitiesAddress.charCodeAt(i) < 0 || securitiesAddress.charCodeAt(i) > 255){
					   	strLength += 3;//漢字編碼在0-255之外，oracle數據庫是UTF-8編碼，一個漢字，對應數據庫varchar2的3個byte。
					  }else{
					  	 strLength += 1;
					  }
				 }
				 if(strLength > 200){
				 	 if (errorMessage != '') errorMessage = errorMessage + '<br>';
    		    	 errorMessage = errorMessage + '地址不可超過200碼!!';
				 }
    		}  
    		/* 備註的驗證 */
    		if(value8 != '')
    		{
				 var count = securitiesNoteCreate.length;
				 var strLength = 0;					 
				 for(var i = 0; i < count; i++){
					  if(securitiesNoteCreate.charCodeAt(i) < 0 || securitiesNoteCreate.charCodeAt(i) > 255){
					   	strLength += 3;//漢字編碼在0-255之外，oracle數據庫是UTF-8編碼，一個漢字，對應數據庫varchar2的3個byte。
					  }else{
					  	 strLength += 1;
					  }
				 }
				 if(strLength > 200){
				 	 if (errorMessage != '') errorMessage = errorMessage + '<br>';
    		    	 errorMessage = errorMessage + '備註不可超過200碼!!';
				 }
    		}    	
            
            if (errorMessage != '')
            {
                showErrorMessageDialog(errorMessage);
                return false;
            }
            
    		return true;
				
		});	
		
		$("#doCancelBtn").click(function() {
			$("#hidden\\.doQueryBtn").trigger('click');
		});
		
		<c:if test="${not empty actionBean.message}">
   			showMessageDialog('<c:out value="${actionBean.message }" escapeXml="false"/>');
		</c:if>	
    });
    
    //-->
    </script>
</head>
<body>

	<div id="smallQueryForm"></div>
<stripes:form id="querySecuritiesForm" beanclass="com.feib.stms.action.Stms9010ActionBean" method="post">
	 <stripes:hidden id="hidden.qrySecuritiesPk" name="viewSecurities.securitiesPk" />           
	<div id="queryForm">
		<table>
						<tr>
				<td colspan="4" class="queryHeader">分公司修改</td>
			</tr>
			<tr>
				<th>分公司代號<span id="mustKeyInStar">**</span></th>
				<td colspan="3">
					<stripes:text id="securitiesNoUpdate" name="viewSecurities.securitiesNo"  size="4" maxlength="4" />
                </td>
			</tr>
			<tr>
				<th>分公司名稱<span id="mustKeyInStar">**</span></th>
				<td colspan="3">
					<stripes:text id="securitiesNameUpdate" name="viewSecurities.securitiesName"  size="40" maxlength="50" />
                </td>
			</tr>
			<tr>
				<th>地址<span id="mustKeyInStar">**</span></th>
				<td colspan="3">
					<stripes:text id="securitiesAddressUpdate" name="viewSecurities.securitiesAddress"  size="40" maxlength="200" />
				</td>
			</tr>
			<tr>
				<th>聯絡人<span id="mustKeyInStar">**</span></th>
				<td colspan="1">
					<stripes:text id="contactNameUpdate" name="viewSecurities.contactName"  size="20" maxlength="50" />
				</td>
				<th>E-MAIL<span id="mustKeyInStar">**</span></th>
				<td colspan="1">
					<stripes:text id="contactEmailUpdate" name="viewSecurities.contactEmail" size="20" maxlength="100" />
				</td>				
			</tr>
			<tr>
				<th>電話號碼<span id="mustKeyInStar">**</span></th>
				<td colspan="1">
					<stripes:text id="contactTelnoUpdate" name="viewSecurities.contactTelno"  size="20" maxlength="20" />
				</td>
				<th>手機號碼<span id="mustKeyInStar">**</span></th>
				<td colspan="1">
					<stripes:text id="contactCellnoUpdate" name="viewSecurities.contactCellno" size="10" maxlength="10" />
				</td>				
			</tr>
			<tr>
				<th>備註</th>
				<td colspan="3">
					<stripes:text id="securitiesNoteUpdate" name="viewSecurities.securitiesNote"  size="30" maxlength="40" />
				</td>
			</tr>
			<tr>
				<th>建立者</th>
				<td colspan="1">
					<stripes:text id="securitiesCreatedByUpdate" name="viewSecurities.createdBy" disabled="true"/>
				</td>
				<th>建立時間</th>
				<td colspan="1">
					<stripes:text id="securitiesCreatedDateUpdate" name="viewSecurities.createdDate" disabled="true"/>
				</td>				
			</tr>
			<tr>
				<th>修改者</th>
				<td colspan="1">
					<stripes:text id="securitiesUpdatedByUpdate" name="viewSecurities.updatedBy" disabled="true"/>
				</td>
				<th>修改時間</th>
				<td colspan="1">
					<stripes:text id="securitiesUpdatedByUpdate" name="viewSecurities.updatedDate" disabled="true"/>
				</td>				
			</tr>	
			<tr>
				<td colspan="5" class="queryFunction">
					<stripes:submit id="doUpdateBtn" name="doUpdate" value="確認" class="formBtn"/>
					<stripes:submit id="doCancelBtn" name="doCancel" value="取消" class="formBtn"/>
				</td>
			</tr>
		</table>
	</div>
			<!--查詢條件-->
			<stripes:hidden id="hidden.qrySecuritiesIdForm" name="qrySecuritiesIdForm" />
			<stripes:hidden id="hidden.qrySecuritiesNameForm" name="qrySecuritiesNameForm" />
			<stripes:hidden id="hidden.queryResult.pageNumber" name="queryResult.pageNumber" />
			<stripes:hidden id="hidden.queryResult.sortCriterion" name="queryResult.sortCriterion" />
			<stripes:hidden id="hidden.queryResult.sortDirection" name="queryResult.sortDirection" />		
			<!--新增表單參數-->
			<stripes:hidden id="hidden.viewSecurities.securitiesNo" name="viewSecurities.securitiesNo" />
			<stripes:hidden id="hidden.viewSecurities.securitiesName" name="viewSecurities.securitiesName" />
			<stripes:hidden id="hidden.viewSecurities.contactName" name="viewSecurities.contactName" />
			<stripes:hidden id="hidden.viewSecurities.contactTelno" name="viewSecurities.contactTelno" />
			<stripes:hidden id="hidden.viewSecurities.contactCellno" name="viewSecurities.contactCellno" />
			<stripes:hidden id="hidden.viewSecurities.contactEmail" name="viewSecurities.contactEmail" />
			<stripes:hidden id="hidden.viewSecurities.securitiesAddress" name="viewSecurities.securitiesAddress" />
			<stripes:hidden id="hidden.viewSecurities.securitiesNote" name="viewSecurities.securitiesNote" />
			
			<stripes:submit id="hidden.doQueryBtn" name="doQuery" value="查詢" class="formBtn" style="display: none;"/>
</stripes:form>
</body>
</html>
